/* ========================================================================= */
/* ------------------------------------------------------------------------- */
/*!		
  \file			edopengl.h
  \date			Jan 2013
  \author		TNick

  \brief		Contains the definition for EdOpenGl class


*//*


 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Please read COPYING and README files in root folder
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
#ifndef __EDOPENGL_INC__
#define __EDOPENGL_INC__
//
//
//
//
/*  INCLUDES    ------------------------------------------------------------ */

#include	<QVBoxLayout>
#include	<QVariant>
#include	<QWidget>

#include	<memtrack.h>
#include	<cpg/cpg_global.h>
#include	<cpg/actions/editorbase.h>
#include	<cpg/logic/cpgdoc.h>

/*  INCLUDES    ============================================================ */
//
//
//
//
/*  DEFINITIONS    --------------------------------------------------------- */

class	FindWidget;

namespace	cpg		{

namespace	Gui		{

/*  DEFINITIONS    ========================================================= */
//
//
//
//
/*  CLASS    --------------------------------------------------------------- */

/**
*	@brief	
*/
class CPGSHARED_EXPORT EdOpenGl		: public QWidget, public EditorBase		{
	Q_OBJECT
	BBM_TRACK( EdOpenGl );
	
	//
	//
	//
	//
	/*  DEFINITIONS    ----------------------------------------------------- */

	/*  DEFINITIONS    ===================================================== */
	//
	//
	//
	//
	/*  DATA    ------------------------------------------------------------ */

private:

	/**
	*	@brief	actual viewer embedded here
	*/
	QWidget				wv_;


	/**
	*	@brief	the layout for our widget
	*/
	QVBoxLayout			lay_;


	/**
	*	@brief	find widget when loaded, NULL when not
	*/
	FindWidget *		find_;


	/*  DATA    ============================================================ */
	//
	//
	//
	//
	/*  FUNCTIONS    ------------------------------------------------------- */

public:


	/**
	*	@brief	constructor;
	*/
	EdOpenGl			( QWidget * parent = NULL );


	/**
	*	@brief	destructor;
	*/
	virtual				~EdOpenGl		( void );


	/* ******************************************************************* */
	/** @name 	Interface methods                                         */
	/* ******************************************************************* */
	///@{


public:


	/**
	*	@brief	the name of this document
	*/
	QString				documentName			( void )
	{ return document()->documentName(); }


	/**
	*	@brief	the path of the file associated with this document
	*/
	QString				filePath				( void )
	{ return document()->filePath(); }


	/**
	*	@brief	the path of the file associated with this document
	*/
	QWidget*			asWidget				( void )
	{ return this; }


	/**
	*	@brief	undo-redo stack
	*/
	QUndoStack*			undoStack				( void )
	{ return document()->undoStack(); }


public slots:


	/**
	*	@brief	save the content to given file or to a different file
	*
	*	As a result internally stored path changes. Modified flag is cleared.
	*/
	bool				fileSave				( const QString & f = QString() )
	{ return document()->fileSave( f ); }


	/**
	*	@brief	initalises the view with a new, editable file
	*/
	bool				fileNew					( void )
	{ return document()->fileNew(); }


	/**
	*	@brief	opens given local file
	*/
	bool				fileOpen				(
			const QString & f, const QString & loc = QString() )
	{ return document()->fileOpen( f, loc ); }


	/**
	*	@brief	opens given resource; the content is not editable
	*/
	bool				openUrl					( const QUrl & url )
	{ return document()->openUrl( url ); }


	/**
	*	@brief	inserts the text at current cursor position
	*/
	void				insertText				( const QString & text )
	{ document()->insertText( text ); }


	/**
	*	@brief	inserts the html content at current cursor position
	*/
	void				insertHtml				(
			const QString & content = QString()
			);


	/**
	*	@brief	inserts a table at current cursor position
	*/
	void				insertTable				( void )
	{ document()->insertTable(); }


	/**
	*	@brief	inserts a column or more at current cursor position
	*
	*	-1 will insert a single column as first column.
	*	0 will insert a number of columns equal to the number of
	*	selected columns.
	*/
	void				insertTableCols			( int count = 1 )
	{ document()->insertTableCols( count ); }


	/**
	*	@brief	removes a column or more at current cursor position
	*/
	void				removeTableCols			( int count = 1 )
	{ document()->removeTableCols( count ); }


	/**
	*	@brief	inserts a row or more at current cursor position
	*
	*	-1 is a special value and inserts a header row.
	*	0 will insert a number of rows equal to the number of
	*	selected rows.
	*/
	void				insertTableRows			( int count = 1 )
	{ document()->insertTableRows( count ); }


	/**
	*	@brief	removes a row or more at current cursor position
	*/
	void				removeTableRows			( int count = 1 )
	{ document()->removeTableRows( count ); }


	/**
	*	@brief	inserts an image at current cursor position
	*/
	void				insertImage			( const QString & s_uri )
	{ document()->insertImage( s_uri ); }


	/**
	*	@brief	select all the content of the document
	*/
	void				selectAll			( void )
	{  /** @todo implement selectAll */ }


	/**
	*	@brief	delets currently selected text
	*/
	void				deleteSel			( void )
	{  /** @todo implement deleteSel */ }


	/**
	*	@brief	cuts currently selected text
	*/
	void				cut					( void )
	{ document()->cut(); }


	/**
	*	@brief	copies currently selected text
	*/
	void				copy				( void )
	{ document()->copy(); }


	/**
	*	@brief	inserts the content of the clipboard
	*/
	void				paste				( void )
	{ document()->paste(); }


	/**
	*	@brief	undoes previous action
	*/
	void				undo				( void )
	{ document()->undo(); }


	/**
	*	@brief	redoes next action
	*/
	void				redo				( void )
	{ document()->redo(); }

	/**
	*	@brief	increases the zoom level
	*/
	void				zoomIn				( qreal amount = 0.10 );


	/**
	*	@brief	decreases the zoom level
	*/
	void				zoomOut				( qreal amount = 0.10 );


	/**
	*	@brief	change the zoom level
	*/
	void				setZoom				( qreal value = 1 );


	/**
	*	@brief	scroll the view to the named anchor
	*/
	void				goToAnchor			( const QString & s_name );


	/**
	*	@brief	changes the visibility of the find box
	*/
	void				showFind			( bool b_visible = false );


	/**
	*	@brief	find the text
	*/
	void				findNext			( const QString & s_text )
	{ document()->findNext( s_text ); }



	/**
	*	@brief	find the text
	*/
	void				findPrev			( const QString & s_text )
	{ document()->findPrev( s_text ); }


	/**
	*	@brief	replace all occurances
	*/
	void				replaceAll			( const QString & s_find, const QString & s_repl )
	{ document()->replaceAll( s_find, s_repl ); }


	/**
	*	@brief	replace first occurance
	*/
	void				replaceNext			( const QString & s_find, const QString & s_repl )
	{ document()->replaceNext( s_find, s_repl ); }


	/**
	*	@brief	replace current occurance, if any
	*/
	void				replaceOne			( const QString & s_find, const QString & s_repl )
	{ document()->replaceOne( s_find, s_repl ); }


public:


	/**
	*	@brief	tell if there is an associated file or not (new or url)
	*/
	bool				isUntitled				( void ) const
	{ return document()->isUntitled(); }


	/**
	*	@brief	tell if there are unsaved changes
	*/
	bool				isModified				( void ) const
	{ return document()->isModified(); }


	/**
	*	@brief	color for filling containers
	*/
	QColor				fillColor				( void )
	{ return document()->fillColor(); }


	/**
	*	@brief	primary color
	*/
	QColor				primColor				( void )
	{ return document()->primColor(); }


	/**
	*	@brief	tell if the cursor is inside a table
	*/
	bool				inTable					( void ) const
	{ return document()->inTable(); }


	/**
	*	@brief	set the read only flag
	*/
	inline void			setReadOnly				( void )
	{ document()->setReadOnly(); }


	/**
	*	@brief	reset the read only flag
	*/
	inline void			resetReadOnly			( void )
	{ document()->resetReadOnly(); }


	/**
	*	@brief	tell if the document is read-only
	*/
	inline bool			isReadOnly				( void ) const
	{ return document()->isReadOnly(); }


	/**
	*	@brief	tell if the document has selection
	*/
	inline bool			hasSelection			( void ) const
	{ return false; /** @todo implement hasSelection */ }


	/**
	*	@brief	tell if the document has selection
	*/
	inline qreal		crtZoom					( void ) const
	{ return 1; /** @todo implement crtZoom */ }


	/**
	*	@brief	tell if the document's find box is visible
	*/
	bool				isFindVisible			( void ) const
	{ return ( find_ != NULL ); }



	///@}
	/* ******************************************************************* */
signals:


	/**
	*	@brief	the content has been edited
	*/
	void			contentChanged				( void );


	/**
	*	@brief	a request to open a local file is issued
	*/
	void			openFileUReq				(
			const QString & s_path,
			const QString & s_loc
			);


	/**
	*	@brief	a request to open an external resource
	*/
	void			openLinkUReq				( const QUrl & req_url );


	/**
	*	@brief	selection in editor has changed
	*/
	void			selectionChanged			( void );


	/**
	*	@brief	the find widget is becoming visible or hidden
	*/
	void			findVisibilityChanged		( bool b_vis );


	/**
	*	@brief	contextual menu
	*/
	void			contextMenu					( const QPoint & pt );


	/**
	*	@brief	emmited when we begin the process of exporting content
	*/
	void			exportStarted				( void );


	/**
	*	@brief	informs that a file was created/opened as an output file
	*/
	void			outputFileOpened			( const QString & s );


	/**
	*	@brief	emmited when we end the process of exporting content
	*/
	void			exportEnded					( bool b_result );


private slots:


	/**
	*	@brief	connected to changed signal of the document
	*/
	void			contentEdited				( void );


	/**
	*	@brief	connected to fileNameModified signal of the document
	*/
	void			fileNameModified			( const QString & new_name );



	/**
	*	@brief	the user clicked a link
	*/
	void			internalLinkReq				( const QUrl & req_url );


private:


	/**
	*	@brief	content of the selection as text
	*/
	QString			selectedText				( void );


	
	/*  FUNCTIONS    ======================================================= */
	//
	//
	//
	//

};	/*	class EdOpenGl	*/

/*  CLASS    =============================================================== */
//
//
//
//

}	//	namespace	Gui

}	//	namespace	cpg

#endif // __EDOPENGL_INC__
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
